home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / manageme / tcpdump-.7 / tcpdump- / tcpdump-richard-1.7 / tcpdump-3.0 / print-arp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-15  |  3.6 KB  |  122 lines

  1. /*
  2.  * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that: (1) source code distributions
  7.  * retain the above copyright notice and this paragraph in its entirety, (2)
  8.  * distributions including binary code include the above copyright notice and
  9.  * this paragraph in its entirety in the documentation or other materials
  10.  * provided with the distribution, and (3) all advertising materials mentioning
  11.  * features or use of this software display the following acknowledgement:
  12.  * ``This product includes software developed by the University of California,
  13.  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14.  * the University nor the names of its contributors may be used to endorse
  15.  * or promote products derived from this software without specific prior
  16.  * written permission.
  17.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20.  */
  21.  
  22. #ifndef lint
  23. static char rcsid[] =
  24.     "@(#) $Header: print-arp.c,v 1.28 94/06/14 20:17:36 leres Exp $ (LBL)";
  25. #endif
  26.  
  27. #include <sys/param.h>
  28. #include <sys/time.h>
  29. #include <sys/socket.h>
  30.  
  31. #include <net/if.h>
  32.  
  33. #include <netinet/in.h>
  34. #include <netinet/if_ether.h>
  35.  
  36. #include <stdio.h>
  37.  
  38. #include "interface.h"
  39. #include "addrtoname.h"
  40.  
  41. static u_char ezero[6];
  42.  
  43. void
  44. arp_print(register const u_char *bp, int length, int caplen)
  45. {
  46.     register const struct ether_arp *ap;
  47.     register const struct ether_header *eh;
  48.     const u_char *p;
  49.     int pro, hrd, op;
  50.  
  51.     ap = (struct ether_arp *)bp;
  52.     if ((u_char *)(ap + 1) > snapend) {
  53.         printf("[|arp]");
  54.         return;
  55.     }
  56.     if (length < sizeof(struct ether_arp)) {
  57.         (void)printf("truncated-arp");
  58.         default_print((u_char *)ap, length);
  59.         return;
  60.     }
  61.     /*
  62.      * Don't assume alignment.
  63.      */
  64.     p = (u_char*)&ap->arp_pro;
  65.     pro = (p[0] << 8) | p[1];
  66.     p = (u_char*)&ap->arp_hrd;
  67.     hrd = (p[0] << 8) | p[1];
  68.     p = (u_char*)&ap->arp_op;
  69.     op = (p[0] << 8) | p[1];
  70.  
  71.     if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL)
  72.         || ap->arp_hln != sizeof(SHA(ap))
  73.         || ap->arp_pln != sizeof(SPA(ap))) {
  74.         (void)printf("arp-#%d for proto #%d (%d) hardware #%d (%d)",
  75.                 op, pro, ap->arp_pln,
  76.                 hrd, ap->arp_hln);
  77.         return;
  78.     }
  79.     if (pro == ETHERTYPE_TRAIL)
  80.         (void)printf("trailer-");
  81.     eh = (struct ether_header *)packetp;
  82.     switch (op) {
  83.  
  84.     case ARPOP_REQUEST:
  85.         (void)printf("arp who-has %s", ipaddr_string(TPA(ap)));
  86.         if (bcmp((char *)ezero, (char *)THA(ap), 6) != 0)
  87.             (void)printf(" (%s)", etheraddr_string(THA(ap)));
  88.         (void)printf(" tell %s", ipaddr_string(SPA(ap)));
  89.         if (bcmp((char *)ESRC(eh), (char *)SHA(ap), 6) != 0)
  90.             (void)printf(" (%s)", etheraddr_string(SHA(ap)));
  91.         break;
  92.  
  93.     case ARPOP_REPLY:
  94.         (void)printf("arp reply %s", ipaddr_string(SPA(ap)));
  95.         if (bcmp((char *)ESRC(eh), (char *)SHA(ap), 6) != 0)
  96.             (void)printf(" (%s)", etheraddr_string(SHA(ap)));
  97.         (void)printf(" is-at %s", etheraddr_string(SHA(ap)));
  98.         if (bcmp((char *)EDST(eh), (char *)THA(ap), 6) != 0)
  99.             (void)printf(" (%s)", etheraddr_string(THA(ap)));
  100.         break;
  101.  
  102.     case REVARP_REQUEST:
  103.         (void)printf("rarp who-is %s tell %s",
  104.             etheraddr_string(THA(ap)),
  105.             etheraddr_string(SHA(ap)));
  106.         break;
  107.  
  108.     case REVARP_REPLY:
  109.         (void)printf("rarp reply %s at %s",
  110.             etheraddr_string(THA(ap)),
  111.             ipaddr_string(TPA(ap)));
  112.         break;
  113.  
  114.     default:
  115.         (void)printf("arp-#%d", op);
  116.         default_print((u_char *)ap, caplen);
  117.         return;
  118.     }
  119.     if (hrd != ARPHRD_ETHER)
  120.         printf(" hardware #%d", ap->arp_hrd);
  121. }
  122.